package com.wp.controller;

import com.github.pagehelper.PageInfo;
import com.wp.entity.Dept;
import com.wp.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: WangPeng
 * @createTime: 2022/11/17 16:02
 * @description:
 * @version: v1.0
 */

@RestController
@RequestMapping("/dept")
@Api(tags = "部门表的增删改查")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping("/list")
    @ApiOperation(value = "查询所有部门")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前显示第几页",name = "current",dataType = "int",required = true,defaultValue = "1"),
            @ApiImplicitParam(value = "每页显示几条",name = "pageSize",dataType = "int",required = true,defaultValue = "5")})
    public PageInfo<Dept> getAlldept(int current, Integer pageSize){
        return deptService.getAllDept(current,pageSize);
    }

    @GetMapping("/delete")
    @ApiOperation(value = "根据部门Id删除部门")
    @ApiImplicitParam(value = "部门id",name = "id",dataType = "int",defaultValue = "93",required = true)
    public int deleteById(int id){
        return deptService.deleteById(id);
    }

    @PostMapping("/addaa")
    @ApiOperation(value = "添加部门信息")
    public int addDept(@RequestBody Dept dept){
        return  deptService.insertDept(dept);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改部门信息")
    public int updateById(@RequestBody Dept dept){
        return deptService.updateById(dept);
    }

}
